﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Utils;
using System.IO;
using DevExpress.Web.ASPxTreeList;
using System.Drawing;

public partial class UserControl_ControlReportSoDoPhanCapTDV : System.Web.UI.UserControl
{
    ClassExecute.ClassExecute dt;
    string str = webapp4U.Configuration.CurrentConnectionString;
    string error = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
          
        }
        else
        {
            if (Session["db"] != null)
            {
                DataTable db = (DataTable)Session["db"];
                ASPxTreeList1.DataSource = db;
                ASPxTreeList1.DataBind();
            }
        }
    }
    void ShowMessageBox(string text)
    {
        MessageBox.Text = text;
        MessageBox.ShowOnPageLoad = true;
    }
   
    protected void imgBtnAdd_Click(object sender, ImageClickEventArgs e)
    {
        dt = new ClassExecute.ClassExecute();
        try
        {
            if (ViewState["Adncode"] == null)
            {
                ViewState["Adncode"] = dt.GetDataDepend(str, "[k_getAdncode]", CommandType.StoredProcedure, ref error,
                           new SqlParameter("@Username", Session["user"].ToString()));
            }

            DataTable db = dt.Get_Data_DataTable(str, ref error, "[k_reportThongTinTuyenDuong]", CommandType.StoredProcedure,
                    new SqlParameter("@Adncode", ViewState["Adncode"].ToString()));

            if (db.Rows.Count > 0)
            {


                ASPxTreeList1.DataSource = db;
                Session["db"] = db;

            }
            else
            {
                if (Session["db"] != null)
                {
                    Session["db"] = null;
                }
                ASPxTreeList1.DataSource = null;
                ShowMessageBox("Dữ liệu không có");
            }
            ASPxTreeList1.DataBind();

        }
        catch (Exception ex)
        {

            string method = System.Reflection.MethodBase.GetCurrentMethod().Name;
            dt.WriteErrorLog(Server.MapPath(webapp4U.Globals.LogUrl()), ex.Message, method);
        }
    }
    protected void imgBtnSave_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            ASPxTreeList1.ExpandAll();
            string filename = DateTime.Now.Year.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Day.ToString() + "_" + "PhanTuyen";
            ASPxTreeListExporter1.WriteXlsToResponse(filename);
        }
        catch
        {

        }
    }
}